import React, { Component } from 'react';
import {Input,Button} from 'antd'
import { connect } from 'react-redux'
import { login,outlogin } from '../../actions/index'

class Login extends Component{
    constructor(){
        super()
        this.state={
            username:'',
            password:''
        }
    }
    onChangeUserName(e){
        this.setState({ username: e.target.value });
    }
    onChangePassword(e){
        this.setState({ password: e.target.value });
    }
    submit(){
        this.props.logindata(this.state)
        this.props.history.push({pathname:'/goods'})
    }
    

    render(){
        const {username,password}=this.state;
        return (
            <div>
                <Input placeholder="用户名" vlaue={username} onChange={this.onChangeUserName.bind(this)}/>
                <Input placeholder="密码" type="password" value={password} onChange={this.onChangePassword.bind(this)}/> 
                <Button type="primary" onClick={this.submit.bind(this)}>登录</Button>  
            </div> 
        )
    }
}


export default connect(({tologin})=>({
    tologin:tologin.logininfo
}),(dispatch)=>({
    logindata(data){
        dispatch(login(data))
    },
    out(){
        dispatch(outlogin())
    }
}))(Login)